#!/bin/bash
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PYTHON_SCRIPT="$SCRIPT_DIR/generate_kafka.py"
LOG_FILE="/opt/logs/fake_data_generat/kafka_producer.log"

mkdir -p "$(dirname "$LOG_FILE")"

HOUR=$(date +"%H")

# 根据时间段决定生成数量
if [[ $HOUR -ge 10 && $HOUR -lt 11 ]] || [[ $HOUR -ge 17 && $HOUR -lt 19 ]]; then
    COUNT=$((RANDOM % 301 + 500))  # 500-800
elif [[ $HOUR -ge 0 && $HOUR -lt 6 ]]; then
    COUNT=$((RANDOM % 51 + 50))    # 50-100
else
    COUNT=$((RANDOM % 101 + 200))  # 200-300
fi

echo "[$(date '+%Y-%m-%d %H:%M:%S')] Starting to send $COUNT records to Kafka over 1 hour..." >> "$LOG_FILE"
/opt/servers/anaconda3/bin/python3 "$PYTHON_SCRIPT" "$COUNT" >> "$LOG_FILE" 2>&1
echo "[$(date '+%Y-%m-%d %H:%M:%S')] Finished sending $COUNT records." >> "$LOG_FILE"
>"$LOG_FILE"